package com.databaseconnectionmobilapi.controller.mysql;

import com.databaseconnectionmobilapi.domain.dto.*;
import com.databaseconnectionmobilapi.service.mysql.MysqlOpService;
import com.databaseconnectionmobilapi.util.result.RestResult;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.sql.SQLException;
import java.util.List;

@RestController
@RequestMapping("/mysql")
@AllArgsConstructor
public class MysqlOpController {
    private MysqlOpService mysqlOpService;

    @RequestMapping("/select/database")
    public RestResult selectDatabaseNames(@RequestBody SelectDatabaseNamesDTO selectDatabaseNamesDTO) {
        return mysqlOpService.selectDatabaseNames(selectDatabaseNamesDTO.getId());
    }

    @RequestMapping("/all/charset")
    public RestResult selectAllCharset(@RequestBody SelectAllCharsetDTO selectAllCharsetDTO) {
        return mysqlOpService.selectAllCharset(selectAllCharsetDTO.getId());
    }

    @RequestMapping("/all/collation")
    public RestResult selectAllCollation(@RequestBody SelectAllCollationDTO selectAllCharsetDTO) {
        return mysqlOpService.selectAllCollation(selectAllCharsetDTO);
    }

    @RequestMapping("/add/database")
    public RestResult addMysqlDatabase(@RequestBody AddMysqlDatabaseDTO addMysqlDatabaseDTO) throws SQLException {
        return mysqlOpService.addMysqlDatabase(addMysqlDatabaseDTO);
    }

    @RequestMapping("/del/database")
    public RestResult delMysqlDatabase(@RequestBody DelMysqlDatabaseDTO delMysqlDatabaseDTO) throws SQLException {
        return mysqlOpService.delMysqlDatabase(delMysqlDatabaseDTO);
    }

    @RequestMapping("/update/database")
    public RestResult updateMysqlDatabase(@RequestBody UpdateMysqlDatabaseDTO updateMysqlDatabaseDTO) throws SQLException {
        return mysqlOpService.updateMysqlDatabase(updateMysqlDatabaseDTO);
    }

    @RequestMapping("/all/table")
    public RestResult selectAllTable(@RequestBody SelectAllTableDTO selectConnectionDTO) {
        return mysqlOpService.selectAllTable(selectConnectionDTO);
    }

    @RequestMapping("/add/table")
    public RestResult addTable(@RequestBody AddTableDTO addTableDTO) throws SQLException {
        return mysqlOpService.addTable(addTableDTO);
    }

    @RequestMapping("/del/table")
    public RestResult delTable(@RequestBody DelTableDTO delAllTableDTO) throws SQLException {
        return mysqlOpService.delTable(delAllTableDTO);
    }

    @RequestMapping("/update/table")
    public RestResult updateTable(@RequestBody UpdateTableDTO updateDbDTO) throws SQLException {
        return mysqlOpService.updateTable(updateDbDTO);
    }

    @RequestMapping("/select/table/struct")
    public RestResult selectTableStruct(@RequestBody SelectTableStructDTO selectTableStructDTO) {
        return mysqlOpService.selectTableStruct(selectTableStructDTO);
    }

    @RequestMapping("/select/data")
    public RestResult selectData(@RequestBody SelectDataDTO selectDataDTO) {
        return mysqlOpService.selectData(selectDataDTO);
    }
}
